import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // {
  //   path: '/article',
  //   component: Layout,
  //   name: 'article',
  //   meta: { title: '文章管理', icon: 'el-icon-s-shop', affix: true },
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'new',
  //       component: () => import('@/views/blogContent/new/New'),
  //       name: 'new',
  //       meta: { title: '内容创作', icon: 'el-icon-edit', affix: true }
  //     },
  //     {
  //       path: 'list',
  //       component: () => import('@/views/blogContent/List'),
  //       name: 'list',
  //       meta: { title: '文章列表', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'main_relation',
  //       component: () => import('@/views/blogContent/MainRelation'),
  //       name: 'main_relation',
  //       meta: { title: '网站专栏', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'sort_relation',
  //       component: () => import('@/views/blogContent/SortRelation'),
  //       name: 'sort_relation',
  //       meta: { title: '分类专栏', icon: 'dashboard', affix: true }
  //     },
  //     {
  //       path: 'new_markdown',
  //       component: () => import('@/views/blogContent/new/NewMarkDown'),
  //       name: 'ContentArticleNewMarkdown',
  //       hidden: true
  //     },
  //     {
  //       path: 'new_richtext',
  //       component: () => import('@/views/blogContent/new/NewRichText'),
  //       name: 'ContentArticleNewRichText',
  //       hidden: true
  //     }
  //   ]
  // },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: '个人信息',
        meta: { title: '个人信息', icon: 'user', noCache: true }
      }
    ]
  }
]

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
